package com.hibegin.http.server.web;

import com.hibegin.http.server.impl.HttpRequest;
import com.hibegin.http.server.impl.HttpResponse;
import com.hibegin.http.server.util.HttpMethod;
import com.szwistar.common.ERR;

/**
 * 拦截器：统一处理 OPTIONS 方法请求
 */
public class Interceptor4HttpOptionsMethod implements Interceptor {
    @Override
    public boolean doInterceptor(HttpRequest request, HttpResponse response) throws Exception {
    	if(request.getMethod() == HttpMethod.OPTIONS) {
    		// 在响应头里增加跨域处理
    		response.addHeader("Access-Control-Allow-Origin", "*");
            response.renderCode(ERR.HTTP_OK);
            return false;
    	}
    	return true;
    }
}
